home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / filesyst / xiafs / xiafspgm.8 / xiafspgm / xiafspgm-0.8.1 / converter.c < prev    next >
C/C++ Source or Header  |  1993-03-21  |  1KB  |  56 lines

  1. /*----------------------------------------------------------------------*
  2.  * converter.c                                *
  3.  *                                    *
  4.  * Copyright (C) Q. Frank Xia, 1993.  All rights reserved.              *
  5.  *                                                     *
  6.  * This software may be redistributed as per Linux copyright        *
  7.  *                                    *
  8.  -----------------------------------------------------------------------*/
  9.  
  10.  
  11. #include <stdio.h>
  12. #include <stdlib.h>
  13. #include <unistd.h>
  14.  
  15. #define MINIX_HEADER 32
  16.  
  17. void die(char * str)
  18. {
  19.     fprintf(stderr,"convert: %s\n", str);
  20.     exit(1);
  21. }
  22.  
  23. int main(int argc, char ** argv)
  24. {
  25.     int i;
  26.     unsigned char buf[1024];
  27.  
  28.     if ( *(argv[1]) != 'o' ) {
  29.         for (i=0; i < 1024; i++) buf[i]=0;
  30.     if (read(0, buf, MINIX_HEADER) != MINIX_HEADER 
  31.         || ((long *) buf)[0] != 0x04100301
  32.         || ((long *) buf)[1] != MINIX_HEADER
  33.         || ((long *) buf)[3] != 0
  34.         || ((long *) buf)[4] != 0
  35.         || ((long *) buf)[5] != 0
  36.         || ((long *) buf)[7] != 0 )
  37.         die("bad file format");
  38.     }
  39.     if ( read(0, buf, 1024) != 512
  40.     || (*(unsigned short *)(buf+510)) != 0xAA55 )
  41.         die("bad file format");
  42.  
  43.     fprintf(stdout, "unsigned char %s[512]={\n", argv[1]);
  44.     for (i=0; i < 512; i++) {
  45.         if ( !(i & 7) )
  46.         fprintf(stdout, "   ");
  47.     fprintf(stdout, " 0x%02X", buf[i]);
  48.     if ( i != 511 )
  49.         fprintf(stdout, ",");
  50.     if ( !((i+1) & 7) )
  51.         fprintf(stdout, "\n");
  52.     }
  53.     fprintf(stdout, "};\n");
  54.     exit(0);
  55. }
  56.